using System;
using System.ServiceModel;
using RentalOfCars.Server.Domain.Database;

namespace RentalOfCars.Server.Infrastructure.ClientServerInterface
{
    public class CarsServiceHost : ServiceHost
    {
        private readonly IDbAccessor _accessor;

        public CarsServiceHost(IDbAccessor accessor, Type serviceType, params Uri[] baseAddresses)
            : base(serviceType, baseAddresses)
        {
            _accessor = accessor;
            if (accessor == null)
            {
                throw new ArgumentNullException("accessor");
            }

            foreach (var contractDescription in ImplementedContracts.Values)
            {
                contractDescription.Behaviors.Add(new CarsServiceHostInstanceProvider(_accessor));
            }
        }
    }
}